#!/bin/sh
# chkconfig: 3 99 01
# description: Starts and stops the crontab_monitor daemon
#

####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi


start_crontab() {
        KIND="BD CRONTAB MONITOR"
	echo -n $"Starting $KIND services: "
	daemon /bigdaddy/crontab_monitor
	RETVAL=$?
	echo
        RETVAL=1
	return $RETVAL
}

start_excheck() {
        KIND="BD EXTERNAL CHECKER"
	echo -n $"Starting $KIND services: "
	daemon /bigdaddy/external_check
	RETVAL=$?
	echo
        RETVAL=1
	return $RETVAL
}

start_monitor() {
        KIND="BD SERVER MONITORING"
	echo -n $"Starting $KIND services: "
	daemon /bigdaddy/server_monitor
	RETVAL=$?
	echo
        RETVAL=1
	return $RETVAL
}

stop_crontab() {
        KIND="BD CRONTAB MONITOR"
	echo -n $"Shutting down $KIND services: "
	killproc crontab_monitor
        RETVAL=$?
	echo ""
	return $RETVAL
}

stop_excheck() {
        KIND="BD EXTERNAL CHECKER"
	echo -n $"Shutting down $KIND services: "
	killall external_check
        RETVAL=$?
	echo ""
	return $RETVAL
}


stop_monitor() {
        KIND="BD SERVER MONITORING"
	echo -n $"Shutting down $KIND services: "
	killproc server_monitor
        RETVAL=$?
	echo ""
	return $RETVAL
}




case "$1" in
	start)
		start_crontab
		start_excheck
		start_monitor
    ;;

	stop)
		stop_crontab
		stop_excheck
		stop_monitor
	;;

	restart)
		stop_crontab
		stop_excheck
		stop_monitor
		start_crontab
		start_excheck
		start_monitor
	;;

	*)
		echo $"Usage: $0 {start|stop|restart}"
		exit 1

esac

exit $?
